﻿-var table = ViewData["DataTable"] as DataTable
-Dictionary<string, decimal> total = ViewData.ContainsKey("total")  ? ViewData["total"] as Dictionary<string,decimal> : null
=HTMLHelper.HiddenInput("tablecontroller",ViewData["Controller"])
#tableholder
  -var count = table.Columns.Count;
  %table.data{width="100%"}
    %tr
      -int i = 1;
      -foreach(DataColumn c in table.Columns)
        %th{id=c.ColumnName, name=c.ColumnName, title=c.Caption, class="nowrap small" + ((i == count) ? " last" : "")}
          =c.Caption
        -i++;
    -bool odd = true
    -foreach(DataRow r in table.Rows)
      -odd = !odd
      %tr{class=(odd ? "odd " : "")}
        -i = 1;
        -bool isDigit = false;
        -foreach(DataColumn c in table.Columns)
          -isDigit = c.DataType == typeof(decimal)
          %td{class= ((i == count) ? "last" : "") + ((isDigit || c.DataType == typeof(int)) ? " right" : "")}
            -if (isDigit)
              =((decimal)r[c]).FormatNumber()
            -else
              =r[c].ToString()
            -i++;
    -if(total != null)
      %tr.total
        -var isFirst = true;
        -i = 1;
        -foreach(var k in total.Keys)
          %td{class=((i == count) ? "last" : "") + ((!isFirst) ? " right": "")}
            -if (isFirst)
              Итого
              -isFirst = false               
            -else if(total[k] != -1)
              =((decimal)total[k]).FormatNumber()
            -i++;